package servlet;

import domain.Product;
import org.apache.commons.beanutils.BeanUtils;
import service.ProductService;
import service.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/10/25.
 */
@WebServlet(name = "EditServlet",urlPatterns = "/editServlet")
public class EditServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
        Product product=new Product();
        try {
            BeanUtils.populate(product,request.getParameterMap());
        } catch (Exception e) {
            e.printStackTrace();
        }
        ProductService ps=new ProductServiceImpl();
        try {
            Boolean flag=ps.update(product);
            response.sendRedirect("/untitled/showListServlet");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
